Marginal effectsとその周辺

多変量回帰・・・好きですか?

Nozomi Niimi

東京医療センター総合内科

2025-07-12

回帰分析について

皆さん多変量回帰は好きですか?

  • 古くから研究されつくされており、信頼感がある

  • 多くの統計ソフトに入っており、行うのが簡単

  • 解釈性が高く、分かりやすい

  • 本当?

多変量回帰は簡単?

Many regression species

  • 多変量回帰は多くの種類がある
    • 0/1でLogistic回帰
    • 整数値だとPoisson回帰
    • 順序ロジット
    • Censored regression(Cox回帰もこのうち)
  • 選択肢が多く、その分どうすればよいのか分からない!

例えば・・・・・・

  • ICU入室患者に対してRHCが予後を改善するかをみた観察研究(Connors et al. 1996)
    • Propensity scoreを広めた研究としても有名
  • 例えば、RHCが半年以内の死亡と関連するかをロジスティック回帰で解析をする
Base
RHC 1.16 [1.01, 1.32]
Not CHF 1.71 [1.29, 2.25]
Age 1.03 [1.03, 1.04]
Num.Obs. 5733
AIC 6882.7
BIC 7089.0
Log.Lik. -3410.366
RMSE 0.45
  • 結果として、RHCは半年以内の死亡と関連する!
  • しかし、ここで上司からのつっこみ

上司からのつっこみ①

結果①

Base Interact
RHC 1.16 [1.01, 1.32] 1.52 [1.02, 2.26]
Not CHF 1.71 [1.29, 2.25] 1.94 [1.40, 2.69]
Age 1.03 [1.03, 1.04] 1.03 [1.03, 1.04]
RHC:Not CHF 0.74 [0.49, 1.12]
Num.Obs. 5733 5733
AIC 6882.7 6882.7
BIC 7089.0 7095.7
Log.Lik. -3410.366 -3409.366
RMSE 0.45 0.45

上司からのつっこみ②

結果②

Base Interact Spline
RHC 1.16 [1.01, 1.32] 1.52 [1.02, 2.26]
Not CHF 1.71 [1.29, 2.25] 1.94 [1.40, 2.69]
Age 1.03 [1.03, 1.04] 1.03 [1.03, 1.04] 1.04 [1.03, 1.05]
RHC:Not CHF 0.74 [0.49, 1.12]
swang1=RHC 1.49 [1.00, 2.23]
cat_chf=Others 1.94 [1.40, 2.70]
age' 0.99 [0.96, 1.01]
age'' 1.04 [0.89, 1.21]
swang1=RHC * cat_chf=Others 0.75 [0.49, 1.14]
Num.Obs. 5733 5733 5733
R2 0.140
AIC 6882.7 6882.7 6884.1
BIC 7089.0 7095.7 7110.3
Log.Lik. -3410.366 -3409.366
RMSE 0.45 0.45

最終的に・・・・・・

例えば、2つの連続値をSplineで表したの場合

  • 解釈・・・・・・

我々はどこにいる?

こんな時にJAMA!

我々(臨床医)のしたい事

  • 根本的な問いかけ
    • 「誰への治療効果ですか?」
    • 「どうやった時の治療効果ですか?」

線形回帰の係数だと駄目な理由は?

  • 線形回帰の係数の解釈 = 条件付き期待値
    • 他の値を固定した時に、その因子を1単位変化した時の平均的なアウトカムの変化量
  • その結果、係数(OR, HRなど)という1つの値にまるめてしまう
  • 複雑な関係性をこの係数のみを報告する事で逆にわかりにくくなる事もある

じゃあ、どうやって報告する?

  • 「誰に?」「何が?」「どのくらい?」変化したら、アウトカムが変化するか?
  • 難しい言葉でいうと“Estimand”を報告する必要がある
  • 例えば
    1. 群全体: ATE
    2. 治療を受けた群全体: ATT
    3. 治療を受けなかった群全体: ATU

ここまでの纏め

  • 多変量解析は解釈がわかりにくい!
    • 特に、InteractionやSplineが入るとよりわかりにくい
    • 通常の解析だと、結果は集団全体の平均で丸め込まれてしまう
      • Estimandをどうやって出せばいい?

Standardization and the prametric g-formulaの基礎

Marginal effectsという選択肢

  • G-computationを用いて限界効果を出す

G-computation

  • 本来は、結果のStandardizationの手法
  • Estimandを決定する方法もある

G-computationの考え方

実践①

# A tibble: 5,733 × 6
   rowid swang1 estimate conf.low conf.high death_01
   <int> <chr>     <dbl>    <dbl>     <dbl>    <dbl>
 1     1 No RHC    0.606    0.535     0.672        0
 2     2 RHC       0.839    0.787     0.880        1
 3     3 RHC       0.743    0.675     0.801        0
 4     4 No RHC    0.746    0.684     0.800        1
 5     5 RHC       0.872    0.830     0.904        1
 6     6 No RHC    0.780    0.721     0.829        0
 7     7 No RHC    0.585    0.519     0.648        0
 8     8 No RHC    0.287    0.231     0.350        1
 9     9 No RHC    0.315    0.247     0.394        0
10    10 RHC       0.593    0.535     0.648        0
# ℹ 5,723 more rows
# A tibble: 11,466 × 6
   rowid swang1 estimate conf.low conf.high death_01
   <int> <chr>     <dbl>    <dbl>     <dbl>    <dbl>
 1     1 No RHC    0.606    0.535     0.672        0
 2     2 No RHC    0.823    0.768     0.868        1
 3     3 No RHC    0.721    0.651     0.782        0
 4     4 No RHC    0.746    0.684     0.800        1
 5     5 No RHC    0.859    0.815     0.893        1
 6     6 No RHC    0.780    0.721     0.829        0
 7     7 No RHC    0.585    0.519     0.648        0
 8     8 No RHC    0.287    0.231     0.350        1
 9     9 No RHC    0.315    0.247     0.394        0
10    10 No RHC    0.567    0.508     0.623        0
# ℹ 11,456 more rows
  • 行数が2倍(5733→11466)になっている事に注意!
  • swang1列のみ変更したデータセットを作成

実践②


 swang1 Estimate Std. Error    z Pr(>|z|)   S 2.5 % 97.5 %
 No RHC    0.638    0.00792 80.5   <0.001 Inf 0.623  0.654
 RHC       0.666    0.01034 64.4   <0.001 Inf 0.645  0.686

Type: response
  • swang1毎でのestimateを纏める
  • 差をとったらRisk differenceを出せる
  • この結果を変形する事で色々な数値を出せる。

実践②

Risk ratio


 Estimate Pr(>|z|)   S 2.5 % 97.5 %
     1.04   0.0433 4.5     1   1.09

Term: swang1
Type: response
Comparison: ln(mean(RHC) / mean(No RHC))

Odds ratio


 Estimate Pr(>|z|)   S 2.5 % 97.5 %
     1.13   0.0454 4.5     1   1.27

Term: swang1
Type: response
Comparison: ln(odds(RHC) / odds(No RHC))
  • 疫学的にはリスク差(あるいはリスク比)が最も知りたい数値
  • Odds ratioは発生率が低いイベントでないと、Risk ratioと近似出来ない(Cummings 2009)

G-computtionの応用

G-computationの応用~ATE/ATT/ATU

  • 元データのうち、元々Interventionが0/1の群だけで同様の事をするとATT/ATUも推定可能
  • Interventionだけでなくても、興味がある変数を動かす事で周辺効果(marginal effect)を出すことが可能

実践③

  • 例えば、患者背景がCHFでRHCの効果がどうなるかをみたい時
# A tibble: 10,554 × 7
   rowid swang1 cat_chf estimate conf.low conf.high death_01
   <int> <chr>  <chr>      <dbl>    <dbl>     <dbl>    <dbl>
 1     1 No RHC Others     0.606    0.535     0.672        0
 2     2 No RHC Others     0.823    0.768     0.868        1
 3     3 No RHC Others     0.721    0.651     0.782        0
 4     4 No RHC Others     0.746    0.684     0.800        1
 5     5 No RHC Others     0.859    0.815     0.893        1
 6     6 No RHC Others     0.780    0.721     0.829        0
 7     7 No RHC Others     0.585    0.519     0.648        0
 8     8 No RHC Others     0.287    0.231     0.350        1
 9     9 No RHC Others     0.315    0.247     0.394        0
10    10 No RHC Others     0.567    0.508     0.623        0
# ℹ 10,544 more rows
ここから、swang 1の値毎にestimateを平均する

 swang1 Estimate Std. Error    z Pr(>|z|)     S 2.5 % 97.5 %
 No RHC    0.562     0.0306 18.3   <0.001 247.4 0.502  0.622
 RHC       0.651     0.0317 20.5   <0.001 307.8 0.588  0.713

Type: response
# A tibble: 456 × 7
   swang1 cat_chf contrast     estimate conf.low conf.high death_01
   <chr>  <chr>   <chr>           <dbl>    <dbl>     <dbl>    <dbl>
 1 RHC    CHF     RHC - No RHC   0.0967 0.000843     0.193        1
 2 No RHC CHF     RHC - No RHC   0.0904 0.00145      0.179        1
 3 No RHC CHF     RHC - No RHC   0.0793 0.00122      0.157        0
 4 No RHC CHF     RHC - No RHC   0.0945 0.000226     0.189        1
 5 No RHC CHF     RHC - No RHC   0.100  0.00131      0.199        0
 6 No RHC CHF     RHC - No RHC   0.0998 0.00141      0.198        0
 7 No RHC CHF     RHC - No RHC   0.0954 0.00136      0.189        1
 8 RHC    CHF     RHC - No RHC   0.0949 0.00119      0.189        0
 9 No RHC CHF     RHC - No RHC   0.0919 0.00161      0.182        1
10 No RHC CHF     RHC - No RHC   0.0816 0.000612     0.163        1
# ℹ 446 more rows
ここから、患者背景がCHFである患者の平均のRisk ratioを計算する

 Estimate Pr(>|z|)   S 2.5 % 97.5 %
     1.16   0.0474 4.4     1   1.34

Term: swang1
Type: response
Comparison: ln(mean(RHC) / mean(No RHC))

G-computationの応用~Propensity score match

  1. Propensity score matchを計算
  2. Matched cohortを作成(仮想Randomized?)
  3. 残った
  4. どの群を選ぶかでATT/ATE/ATUも簡単に計算可能!(Greifer 2025)

実践④

A `matchit` object
 - method: 1:1 nearest neighbor matching without replacement
 - distance: Propensity score
             - estimated with logistic regression
 - number of obs.: 5733 (original), 4366 (matched)
 - target estimand: ATT
 - covariates: cat_chf, age, sex, race, edu, income, wtkilo1, temp1, meanbp1, resp1, hrt1, pafi1, paco21, ph1, wblc1, hema1, sod1, pot1, crea1, bili1, alb1, cardiohx, chfhx, immunhx, transhx, amihx
# A tibble: 4,366 × 35
   death_yn death_01 death_days swang1 swang_yn cat_chf cat1     age crea1 sex  
      <dbl>    <dbl>      <dbl> <chr>     <dbl> <chr>   <chr>  <dbl> <dbl> <chr>
 1        0        0        180 No RHC        0 Others  COPD    70.3 1.20  Male 
 2        1        1         45 RHC           1 Others  MOSF …  78.2 0.600 Fema…
 3        0        0        180 RHC           1 Others  MOSF …  46.1 2.60  Fema…
 4        1        1         37 No RHC        0 Others  ARF     75.3 1.70  Fema…
 5        1        1          2 RHC           1 Others  MOSF …  67.9 3.60  Male 
 6        0        0        180 No RHC        0 Others  MOSF …  55.0 1     Male 
 7        1        1         38 No RHC        0 Others  ARF     43.6 0.700 Male 
 8        0        0        180 No RHC        0 Others  MOSF …  18.0 1.70  Fema…
 9        0        0        180 RHC           1 Others  ARF     48.4 0.5   Fema…
10        0        0        180 No RHC        0 Others  ARF     34.4 0.5   Male 
# ℹ 4,356 more rows
# ℹ 25 more variables: race <chr>, edu <dbl>, income <chr>, wtkilo1 <dbl>,
#   temp1 <dbl>, meanbp1 <dbl>, resp1 <dbl>, hrt1 <int>, pafi1 <dbl>,
#   paco21 <dbl>, ph1 <dbl>, wblc1 <dbl>, hema1 <dbl>, sod1 <int>, pot1 <dbl>,
#   bili1 <dbl>, alb1 <dbl>, cardiohx <int>, chfhx <int>, immunhx <int>,
#   transhx <int>, amihx <int>, distance <dbl>, weights <dbl>, subclass <fct>

 Estimate Pr(>|z|)   S 2.5 % 97.5 %
     1.03    0.121 3.0 0.992   1.07

Term: swang1
Type: response
Comparison: ln(mean(RHC) / mean(No RHC))

 Estimate Pr(>|z|)   S 2.5 % 97.5 %
     1.03    0.122 3.0 0.992   1.07

Term: swang1
Type: response
Comparison: ln(mean(RHC) / mean(No RHC))

 Estimate Pr(>|z|)   S 2.5 % 97.5 %
     1.03    0.123 3.0 0.992   1.07

Term: swang1
Type: response
Comparison: ln(mean(RHC) / mean(No RHC))

G-computationの応用~Doubly robust

  1. Propensity score weightingを計算
  2. Outcomeを目標とする多変量回帰を作成
  3. 上記を組み合わせてDoubly robustを計算可能
  4. どの群を選ぶかでATT/ATE/ATUも簡単に計算可能!

実践⑤

A weightit object
 - method: "glm" (propensity score weighting with GLM)
 - number of obs.: 5733
 - sampling weights: none
 - treatment: 2-category
 - estimand: ATE
 - covariates: cat_chf, age, sex, race, edu, income, wtkilo1, temp1, meanbp1, resp1, hrt1, pafi1, paco21, ph1, wblc1, hema1, sod1, pot1, crea1, bili1, alb1, cardiohx, chfhx, immunhx, transhx, amihx
# A tibble: 5,733 × 8
   death_01 swang_yn   age sex    race  cat_chf crea1 weights
      <dbl>    <dbl> <dbl> <chr>  <chr> <chr>   <dbl>   <dbl>
 1        0        0  70.3 Male   white Others  1.20     2.01
 2        1        1  78.2 Female white Others  0.600    1.78
 3        0        1  46.1 Female white Others  2.60     2.49
 4        1        0  75.3 Female white Others  1.70     1.53
 5        1        1  67.9 Male   white Others  3.60     3.31
 6        0        0  86.1 Female white Others  1.40     1.12
 7        0        0  55.0 Male   white Others  1        1.61
 8        1        0  43.6 Male   white Others  0.700    1.39
 9        0        0  18.0 Female white Others  1.70     1.39
10        0        1  48.4 Female white Others  0.5      2.04
# ℹ 5,723 more rows
Risk ratio and 95% confidence interval

 Estimate Pr(>|z|)   S 2.5 % 97.5 %
     1.05   0.0291 5.1     1    1.1

Term: swang1
Type: probs
Comparison: ln(mean(RHC) / mean(No RHC))

G-computationの応用~機械学習を用いた手法

  • 厳密にはStandardizationとは違うが・・・・・・
  • Datasetを倍にして機械学習で推定する方法をS-learnerという
  • 因果推定を行う場合は、重み付けも行うD-learnerやX-learnerもある
  • Classificationの場合は信頼区間は簡単には出せないのが難点

実践⑤

# A tibble: 2 × 2
  swang1 mean_death_prob
  <chr>            <dbl>
1 No RHC           0.642
2 RHC              0.655

G-computationの利点

  • 「この集団の介入を変えたら、どの程度良くなるか?」をダイレクトに伝えられる(King, Tomz, and Wittenberg 2000)
    • InteractionやSplineなど複雑な式でもシンプルに結果を伝えられる
  • 予測と因果を両方行う事が可能!

予測~Average marginal prediction

  • 通常のアウトカム式のみで一発勝負 ここはDoubly robustは使っちゃいけない

因果~Average comparison

  • Doubly robustを使った方が安心かもしれない
    • ただし、効率が悪い可能性もあり・・・・・・

G-computationでのAdvancedな統計結果の伝え方

  • 伝えるEstimandを正確に伝える
  • 「誰に」、「もし**したら」、「平均的にどのような効果?」が「どれくらいの確実性」あるかを言う
    • 出来るだけ、臨床的に意味がある差かどうかを考える

G-computationの限界

  • 基本的には通常の回帰と一緒
    • Unobserved confoundingやMisspecificationに弱い
  • 予測の為ではなく因果よりと考えたほうが良い
    • モデル作成でStep wiseや機械学習のようなやり方はしないほうが良い

最後に

Box先生の名言

すべてのモデルは誤っている。しかし、そのうちのいくつかは役に立つ。

RでのMarginal effectsの使い方

Thank you for your listening!!

References

Connors, A F, Jr, T Speroff, N V Dawson, C Thomas, F E Harrell Jr, D Wagner, N Desbiens, et al. 1996. “The Effectiveness of Right Heart Catheterization in the Initial Care of Critically Ill Patients. SUPPORT Investigators.” JAMA: The Journal of the American Medical Association 276 (11): 889–97. https://doi.org/10.1001/jama.276.11.889.
Cummings, Peter. 2009. “The Relative Merits of Risk Ratios and Odds Ratios.” Archives of Pediatrics & Adolescent Medicine 163 (5): 438–45. https://doi.org/10.1001/archpediatrics.2009.31.
Dahabreh, Issa J, and Kirsten Bibbins-Domingo. 2024. “Causal Inference about the Effects of Interventions from Observational Studies in Medical Journals.” JAMA: The Journal of the American Medical Association 331 (21): 1845–53. https://doi.org/10.1001/jama.2024.7741.
Greifer, Noah. 2025. “Estimating Effects After Matching.” https://cran.r-project.org/web/packages/MatchIt/vignettes/estimating-effects.html.
King, Gary, Michael Tomz, and Jason Wittenberg. 2000. “Making the Most of Statistical Analyses: Improving Interpretation and Presentation.” American Journal of Political Science 44 (2): 347–61. https://doi.org/10.2307/2669316.